package com.example.aircraftwar.codes.application.game;

import android.app.Activity;
import android.graphics.Bitmap;

import com.example.aircraftwar.codes.aircraft.BaseEnemyAircraft;
import com.example.aircraftwar.codes.aircraft.BossEnemy;
import com.example.aircraftwar.codes.factory.BossEnemyFactory;


public class DifficultGame extends Game {

    public DifficultGame(Activity context, Bitmap background, boolean videoOpen) {
        super(context, background, videoOpen);
    }

    private int hardDifficultyCount = 1;

    @Override
    public void difficultyControl() {
        if (time / 8000 - hardDifficultyCount >= 0) {
            hardDifficultyCount++;
            eliteGenerationRate = eliteGenerationRate + 0.02;
            attributeRate = attributeRate + 0.05;
            propReductionRate = propReductionRate + 0.02;
        }
    }

    @Override
    public void bossGeneration(){
        // 分数达到阈值时，产生Boss机
        if (score / 200 == bossSign) {
            bossSign ++;
            bossHpAdd += 200;
            bossFlag = true;
            for (BaseEnemyAircraft enemyAircraft : enemyAircrafts) {
                if (enemyAircraft instanceof BossEnemy) {
                    if (!enemyAircraft.notValid()) {
                        bossFlag = false;
                    }
                }
            }
            if (bossFlag) {
                enemyAircraftFactory = new BossEnemyFactory();
                BaseEnemyAircraft enemyAircraft = enemyAircraftFactory.createEnemyAircraft(context);
                enemyAircrafts.add(enemyAircraft);
                context.runOnUiThread(() -> this.addView(enemyAircraft));

                intent_bgm.putExtra("videoOpen", false);
                context.startService(intent_bgm);
                intent_boss.putExtra("videoOpen", videoOpen);
                context.startService(intent_boss);
            }
        }
    }
}
